package com.neusoft.yuejian12.yuejian_12.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.neusoft.yuejian12.yuejian_12.R;
import com.neusoft.yuejian12.yuejian_12.adapter.MyCollectActListAdapter;
import com.neusoft.yuejian12.yuejian_12.javabean.ActivityBean;
import com.neusoft.yuejian12.yuejian_12.listener.RetrofitListener;
import com.neusoft.yuejian12.yuejian_12.model.UserModel;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class MyCollectActActivity  extends Activity implements View.OnClickListener,RetrofitListener<List<ActivityBean>> {
    private Button collectTrain_button,
            collectClub_button,
            collectMaster_button,
            collectMatch_button;
    private ImageView left;

    private int u_id;
    private RecyclerView recyclerView;
    private MyCollectActListAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_collect_list);
        initView();
        initEvents();
        getMyCollectAct();
    }
    private void initView(){
        collectTrain_button=(Button) findViewById(R.id.collectTrain_button);
        collectClub_button=(Button) findViewById(R.id.collectClub_button);
        collectMaster_button=(Button) findViewById(R.id.collectMaster_button);
        collectMatch_button=(Button) findViewById(R.id.collectMatch_button);
        left=(ImageView)findViewById(R.id.left);
        recyclerView=(RecyclerView) findViewById(R.id.my_collect);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));//设置布局


    }
    private void initEvents(){

        //返回上一页
        left.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        //跳转到培训--当前activity
        collectTrain_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = new Intent(MyCollectActActivity.this,MyCollectListActivity.class);
                startActivity(intent);
            }
        });

        //跳转到俱乐部
        collectClub_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = new Intent(MyCollectActActivity.this,MyCollectClubActivity.class);
                startActivity(intent);
            }
        });


        //跳转到大师
        collectMaster_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = new Intent(MyCollectActActivity.this,MyCollectMasterActivity.class);
                startActivity(intent);
            }
        });
        //跳转到比赛
        collectMatch_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = new Intent(MyCollectActActivity.this,MyCollectMatchActivity.class);
                startActivity(intent);
            }
        });
    }
    void getMyCollectAct(){
        SharedPreferences sp = getSharedPreferences("userInfo", Context.MODE_PRIVATE);
        u_id = sp.getInt("u_id", 0);
        UserModel userModel=new UserModel();
        userModel.getMyCollectAct(u_id,"1",this);
    }

    @Override
    public void onSuccess(List<ActivityBean> masterBean){
        adapter = new MyCollectActListAdapter(MyCollectActActivity.this,masterBean);
        recyclerView.setAdapter(adapter);
    }

    @Override
    public void onFail() {
        //showToast("网络发生错误");
    }
    @Override
    public void onClick(View view) {

    }

//    private void initData() {
//        SharedPreferences sp = getSharedPreferences("userInfo", Context.MODE_PRIVATE);
//        u_id = sp.getInt("u_id", 0);
////             Log.d("we","u_id");
//
//        UserModel userModel = new UserModel();
//        //发送请求
//        Call<List<ActivityBean>> call = userModel.getMyCollectAct
//                (u_id,"1");
//        //2.处理结果
//        call.enqueue(new Callback<List<ActivityBean>>() {
//            @Override
//            public void onResponse(Call<List<ActivityBean>> call, Response<List<ActivityBean>> response) {
//                List<ActivityBean> data = (List<ActivityBean>) response.body();  //获取数据
//                recyclerView.setAdapter(new MyCollectActListAdapter(MyCollectActActivity.this, data));
//            }
//
//            @Override
//            public void onFailure(Call<List<ActivityBean>> call, Throwable t) {
//
//            }
//
//        });
//
//    }

}

